package cn.wolfcode.p2p.base.controller;

import cn.wolfcode.p2p.base.domain.Account;
import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.base.service.IAccountService;
import cn.wolfcode.p2p.business.service.IExpAccountService;
import cn.wolfcode.p2p.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 个人中心
 */
@Controller
public class PersonalController {
    @Autowired
    private IAccountService accountService;
    @Autowired
    private IExpAccountService expAccountService;

    /**
     * 个人中心页面
     * 返回视图给前端
     *
     * @return 跳转模板页面
     */
    @RequestMapping("personal")
    public String personal(Model model) {
        //获取到session中的id
        LoginInfo loginInfo = UserContext.getLoginInfo();

        Account account = accountService.getById(loginInfo.getId());
        model.addAttribute("account", account);
        model.addAttribute("expAccount", expAccountService.getById(loginInfo.getId()));
        return "personal";
    }
}
